home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / ghostscript / src / files.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  103 lines

  1. /* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* files.h */
  20. /* Common declarations for zfile.c and zfileio.c */
  21. /* Requires stream.h */
  22.  
  23. /*
  24.  * File objects store a pointer to a stream in value.pfile.
  25.  * A file object is valid if its "size" matches the read_id or write_id
  26.  * (as appropriate) in the stream it points to.  This arrangement
  27.  * allows us to detect closed files reliably, while allowing us to
  28.  * reuse closed streams for new files.
  29.  */
  30. #define fptr(pref) (pref)->value.pfile
  31. #define make_file(pref,a,id,s)\
  32.   make_tasv(pref,t_file,a,id,pfile,s)
  33.  
  34. /* The standard files. */
  35. extern stream *gs_stream_stdin;
  36. extern stream *gs_stream_stdout;
  37. extern stream *gs_stream_stderr;
  38. /* An invalid file. */
  39. extern stream *invalid_file_entry;
  40.  
  41. /* Macros for checking file validity. */
  42. #define check_file_access(svar,op,acc)\
  43.    {    svar = fptr(op);    /* do first, acc may refer to it */\
  44.     if ( !(acc) ) return_error(e_invalidaccess);\
  45.    }
  46. #define check_file_ref(svar,op,acc)\
  47.    {    check_type(*(op), t_file);\
  48.     check_file_access(svar, op, acc);\
  49.    }
  50. #define check_file(svar,op)\
  51.     check_file_ref(svar, op, (svar->read_id | svar->write_id) == r_size(op))
  52.  
  53. /*
  54.  * If a file is open for both reading and writing, its read_id, write_id,
  55.  * and stream procedures and modes reflect the current mode of use;
  56.  * an id check failure will switch it to the other mode.
  57.  */
  58. int file_switch_to_read(P1(ref *));
  59. #define check_read_file(svar,op)\
  60.    {    check_read_type(*(op), t_file);\
  61.     check_file_access(svar, op,\
  62.         (svar->read_id == r_size(op) || file_switch_to_read(op)));\
  63.    }
  64. int file_switch_to_write(P1(ref *));
  65. #define check_write_file(svar,op)\
  66.    {    check_write_type(*(op), t_file);\
  67.     check_file_access(svar, op,\
  68.         (svar->write_id == r_size(op) || file_switch_to_write(op)));\
  69.    }
  70.  
  71. /* Procedures exported by zfile.c. */
  72.     /* for gs.c */
  73. FILE *lib_fopen(P1(const char *));
  74.     /* for gsmain.c */
  75. int lib_file_open(P6(const char *, uint, byte *, uint, uint *, ref *));
  76. int file_read_string(P3(const byte *, uint, ref *));
  77.     /* for os_open in zfiledev.c */
  78. /*int file_open_stream(P6(const byte *, uint, const char *, uint,
  79.   stream **, fdev_proc_fopen_t));*/
  80.     /* for zfilter.c */
  81. int filter_open(P5(const char *, uint, ref *, const stream_procs _ds *,
  82.   stream **));
  83.     /* for zfiledev.c */
  84. int file_close_finish(P1(stream *));
  85. int file_close_disable(P1(stream *));
  86.     /* for gsmain.c, interp.c */
  87. int file_close(P1(ref *));
  88.     /* for zfiledev.c */
  89. stream *file_alloc_stream(P0());
  90.     /* for isave.c */
  91. void file_save(P0());
  92. /*void file_restore(P1(const alloc_save *));*/
  93.  
  94. /* Procedures exported by zfileio.c. */
  95.     /* for zfiledev.c */
  96. int zreadline_from(P4(byte *, uint, uint *, stream *));
  97.     /* for zstring.c */
  98. int ztoken_file(P1(os_ptr));
  99.     /* for interp.c */
  100. int file_check_read(P2(ref *, stream **));
  101.     /* for file_close_finish in zfile.c */
  102. void check_close_current_file(P1(stream *));
  103.